package cz.muni.fi.pa165.travelagency.dto;

import cz.muni.fi.pa165.travelagency.api.entities.ICustomer;
import cz.muni.fi.pa165.travelagency.api.entities.IOrder;
import cz.muni.fi.pa165.travelagency.api.entities.IPackageTour;
import cz.muni.fi.pa165.travelagency.api.entities.ITour;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.adapters.XmlAdapter;

/**
 * Data transfer object of Order
 *
 * @author Marian Mozola
 */
@XmlRootElement
public class OrderDTO implements IOrder {

    private static final long serialVersionUID = 6L;
    private Long id;
    private ICustomer customer;
    private IPackageTour orderedPackageTour;
    private List<ITour> orderedTours = new ArrayList<>();
    private Date created;
    private int numberOfPersons;
    private boolean paid;
    private BigDecimal price;

    public OrderDTO() {
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    @XmlTransient
    public ICustomer getCustomer() {
        return customer;
    }

    @Override
    public void setCustomer(ICustomer customer) {
        this.customer = customer;
    }

    @Override
    @XmlTransient
    public IPackageTour getOrderedPackageTour() {
        return orderedPackageTour;
    }

    @Override
    public void setOrderedPackageTour(IPackageTour orderedPackageTour) {
        this.orderedPackageTour = orderedPackageTour;
    }

    @Override
    @XmlTransient
    public List<ITour> getOrderedTours() {
        return orderedTours;
    }

    @Override
    public void setOrderedTours(List<ITour> orderedTours) {
        this.orderedTours = orderedTours;
    }

    @Override
    public Date getCreated() {
        return created;
    }

    @Override
    public void setCreated(Date created) {
        this.created = created;
    }

    @Override
    public int getNumberOfPersons() {
        return numberOfPersons;
    }

    @Override
    public void setNumberOfPersons(int numberOfPersons) {
        this.numberOfPersons = numberOfPersons;
    }

    @Override
    public boolean isPaid() {
        return paid;
    }

    @Override
    public void setPaid(boolean paid) {
        this.paid = paid;
    }

    @Override
    public BigDecimal getPrice() {
        return price;
    }

    @Override
    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final OrderDTO other = (OrderDTO) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "OrderDTO{" + "id=" + id + ", customer=" + (customer != null ? customer.getId() : null) + ", created=" + created + ", numberOfPersons=" + numberOfPersons + ", paid=" + paid + ", price=" + price + '}';
    }
    
    static class Adapter extends XmlAdapter<OrderDTO,IOrder> {

        @Override
        public IOrder unmarshal(OrderDTO v) throws Exception {
            return v;
        }

        @Override
        public OrderDTO marshal(IOrder v) throws Exception {
            return (OrderDTO) v;
        }
        
    }
}
